package com.aqfeel.services;

import com.aqfeel.models.Item;
import com.aqfeel.repositories.ItemRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ListService {

    @Autowired
    private ItemRepository itemRepository;

    public Iterable<Item> getItems() {
        return itemRepository.findAll();
    }

    public void addItem(Item item) {
        if (itemRepository.exists(item.getId())) {
            throw new IllegalArgumentException("Item with same Id exists");
        }
        itemRepository.save(item);
    }
}
